import * as types from "@/store/actionTypes"
import { getToken } from "@/utils"
const initialState = {
  token: getToken(), // 从本地缓存中获取
  userInfo: {}, // 个人信息是一个空对象
}

export default function user(state = initialState, action) {
  switch (action.type) {
    case types.SETTOKEN:
      return { ...state, token: action.payload }
    case types.SETUSERINFO:
      return { ...state, userInfo: action.payload }
    case types.CLEARTOKEN:
      return { ...state, token: "", userInfo: {} }
    default:
      return state
  }
}
